﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.Models.NumericQuestion>" validateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Numeric Question
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="pageHeadingContainer"><h2 class="pageHeading">Question Editor</h2></div>
    <div id="contentContainer">
        <p>
           <%= Html.ActionLink("Polls > ", "Index", "Poll", null, new { @class = "breadcrumb" })%>
           <%= Html.ActionLink(ViewData["pollName"] + " > ", "Questions", "Poll", new { pollID = ViewData["pollID"], pollName = ViewData["pollName"] }, new { @class = "breadcrumb" })%>
           Question <%= Model.questionNumber %>
        </p>
    <script src="../../Scripts/EditSAQ.js" type="text/javascript"></script>
    
    <% Html.EnableClientValidation();
       var pollRoles = ViewData["pollRoles"] as ICollection<dbPoll_Application.Models.Role>;
       var pollCreator = new dbPoll_Application.Models.Role("Poll Creator");
       var pollAdministrator = new dbPoll_Application.Models.Role("Poll Administrator");
       DateTime? pollClose = ViewData["pollClose"] as DateTime?;
       DateTime? pollStart = ViewData["pollStart"] as DateTime?;
    %>
    <% if (Model.questionID < 0)
       {
           Html.RenderPartial("PageMenu", Model);
       } %>
    <% String actionName;
       if (Model.questionID < 0)
       {
           actionName = "AddNumeric";
       }
       else {
           actionName = "UpdateNumeric";
       } %>
    <%  using (Ajax.BeginForm(actionName, new AjaxOptions { OnSuccess = "onSubmitSuccess" }))
        { %>
        <input type="hidden" id="pollID" value="<%= ViewData["pollID"] %>" name="pollID" />
        <input type="hidden" id="pollName" value="<%= ViewData["pollName"] %>" name="pollName" />    
        <div id="numericQuestionEditorContainer">
            <%= Html.HiddenFor(m => m.questionID)%>
            <%= Html.HiddenFor(m => m.creationTime)%>
            <%= Html.HiddenFor(m => m.deletionTime)%>
            <%= Html.HiddenFor(m => m.type)%>
            <%= Html.HiddenFor(m => m.questionNumber)%>
        
            <ul id="editMCQTable">
                <li id="questionRow"><%= Html.TextAreaFor(m => m.question)%></li>
            </ul>
            <div id="rangeContainer">
                <ul>
                    <% if (Model.questionID < 0)
                       { %>
                    <li><label for="minValue">Greater than</label><%= Html.TextBoxFor(m => m.greaterThan, new { @Value = "" })%></li>
                    <li><label for="maxValue">Less than</label><%= Html.TextBoxFor(m => m.lessThan, new { @Value = "" })%></li>  
                    <% }
                       else
                       { %>
                    <li><label for="minValue">Greater than</label><%= Html.TextBoxFor(m => m.greaterThan)%></li>
                    <li><label for="maxValue">Less than</label><%= Html.TextBoxFor(m => m.lessThan)%></li>
                    <% } %>
                </ul>
                <p>OR</p>
                <span><label for="singleValue">Single value</label><%= Html.TextBox("singleValue") %></span>
            </div>
            <div id="buttons">
                <ul>
                    <li><%= Html.ValidationMessageFor(m => m.question)%></li>
                    <li><%= Html.ValidationMessageFor(m => m.fontColour)%></li>
                    <li id="errorMessage"></li>
                    <li class="left"><input type="submit" value="Save" id="submitForm" /><span id="result"></span></li>
                </ul>
            </div>
        </div>
        <div id="rightColumn">
            <% Html.RenderPartial("QuestionObjects", Model); %>
            <% Html.RenderPartial("QuestionSettings", Model); %>
            <% Html.RenderPartial("ChartSettings", Model); %>
        </div>
        <div class="clear"></div>
        <% } %>
        </div> 
        <script type="text/javascript" >
        <%if  ((!(pollRoles.Contains(pollCreator) || pollRoles.Contains(pollAdministrator)) || pollStart!=null) && ViewData["testPoll"] == "False") 
          {%>document.getElementById("question").readOnly=true;
             if ("<%= pollClose>DateTime.Now%>"=="True")
             {
                 document.getElementById("greaterThan").readOnly=true;
                 document.getElementById("lessThan").readOnly=true;
                 document.getElementById("singleValue").readOnly=true;
             }
        <%} %>
        </script>
</asp:Content>
